"""
API响应模型定义
"""
from pydantic import BaseModel, Field
from typing import List, Dict, Any, Optional
from datetime import datetime


class SentimentEntity(BaseModel):
    """带情感信息的实体模型"""
    start: int = Field(..., description="实体在文本中的起始位置")
    end: int = Field(..., description="实体在文本中的结束位置")
    type: str = Field(..., description="实体类型")
    text: str = Field(..., description="实体文本内容")
    sentiment: str = Field(..., description="情感标签")
    sentiment_prob: float = Field(..., ge=0.0, le=1.0, description="情感概率")
    sentiment_distribution: Dict[str, float] = Field(..., description="情感分布概率")


class HealthResponse(BaseModel):
    """健康检查响应模型"""
    status: str = Field(..., description="服务状态")
    timestamp: datetime = Field(..., description="响应时间戳")
    version: str = Field(..., description="服务版本")


class ModelStatusResponse(BaseModel):
    """模型状态响应模型"""
    model_type: str = Field(..., description="模型类型")
    status: str = Field(..., description="模型状态")
    is_trained: bool = Field(..., description="模型是否已训练")
    last_updated: datetime = Field(..., description="最后更新时间")
    performance_metrics: Dict[str, float] = Field(..., description="性能指标")


class ServiceStatusResponse(BaseModel):
    """服务状态响应模型"""
    status: str = Field(..., description="服务状态")
    timestamp: datetime = Field(..., description="响应时间戳")
    version: str = Field(..., description="服务版本")
    models: Dict[str, Dict[str, Any]] = Field(..., description="各模型状态")


class SentimentResponse(BaseModel):
    """情感分析响应模型"""
    text: str = Field(..., description="输入文本")
    entities: List[SentimentEntity] = Field(..., description="带情感信息的实体列表")
    processing_time: float = Field(..., description="处理时间（秒）")
    timestamp: datetime = Field(..., description="响应时间戳")


class EntityResponse(BaseModel):
    """实体识别响应模型"""
    text: str = Field(..., description="输入文本")
    entities: List[SentimentEntity] = Field(..., description="识别出的实体列表")
    processing_time: float = Field(..., description="处理时间（秒）")
    timestamp: datetime = Field(..., description="响应时间戳")


class BatchSentimentResponse(BaseModel):
    """批量情感分析响应模型"""
    results: List[List[SentimentEntity]] = Field(..., description="批量处理结果")
    processing_time: float = Field(..., description="处理时间（秒）")
    batch_size: int = Field(..., description="批量大小")
    timestamp: datetime = Field(..., description="响应时间戳")